import java.util.ArrayList;
import java.util.PriorityQueue;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }

}
class Solution {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>((s1, s2)-> s2 - s1);
        for (int stone : stones) {
            maxHeap.add(stone);
        }
        while(maxHeap.size() >= 2){
            int x = maxHeap.poll();
            int y = maxHeap.poll();
            if(x != y) maxHeap.add(x - y > 0 ? x - y : y - x);
            System.out.println(maxHeap.peek());
        }
        return maxHeap.isEmpty() ? 0 : maxHeap.poll();
    }
}